<?php

//get all subcategory	
function getAllSubCategory(){
	$qr ="SELECT * FROM subcategory";
	return mysql_query($qr);
}

//get list subcategory	by categoryid
function getListSubCategoryByCategoryID($categoryID){
	$qr ="SELECT * FROM subcategory WHERE CategoryID = $categoryID;";
	return mysql_query($qr);
}

//add subcategory	
function addSubCategory($subCategoryName,$description,$categoryID){
	$qr ="INSERT INTO subcategory(SubCategoryName,Description,CategoryID) VALUES('$subCategoryName','$description','$categoryID')";
	mysql_query($qr);
}

//get subcategory by id	
function getSubCategoryByID($subCategoryID){
	$qr ="SELECT * FROM subcategory WHERE SubCategoryID = $subCategoryID;";
	return mysql_query($qr);
}

//get subcategory by productid
function getSubCategoryByProductID($productID){
	$qr ="SELECT * FROM product WHERE ProductID = $productID;";
	$product = mysql_fetch_array(mysql_query($qr));
	$subCategoryID = $product['SubCategoryID'];
	settype($subCategoryID,"int");
	return getSubCategoryByID($subCategoryID);
}

//edit subcategory	
function editSubCategory($subCategoryName,$description,$categoryID,$subCategoryID){
	$qr ="UPDATE subcategory SET SubCategoryName = '$subCategoryName',Description = '$description' ,CategoryID = '$categoryID' WHERE SubCategoryID = $subCategoryID;";
	mysql_query($qr);
}

//edit subcategory amount total 
function editSubCategoryAmountTotal($subCategoryAmountTotal,$subCategoryID){
	$qr ="UPDATE subcategory SET SubCategoryAmountTotal = '$subCategoryAmountTotal'WHERE SubCategoryID = $subCategoryID;";
	mysql_query($qr);
}

//delete subcategory	
function deleteSubCategory($subCategoryID){
	$qr ="DELETE FROM subcategory WHERE SubCategoryID = $subCategoryID";
	mysql_query($qr);
}

?>